<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        thead tr th{text-align: center!important;}
        tr td{text-align: center!important;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" lay-filter="opinion-table" id="opinion-table"></table>
                    <script type="text/html" id="table-operate">
                        {{#  if(d.status == 1){ }}
                        <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="handle">去处理</a>
                        {{# }}}
                        <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</a>
                    </script>
                    <script type="text/html" id="status">
                        {{#  if(d.status == 1){ }}
                        <span class="layui-badge">未处理</span>
                        {{# }}}
                        {{#  if(d.status == 2){ }}
                        <span class="layui-badge layui-bg-green">已处理</span>
                        {{# }}}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','table'], function(){
        var form = layui.form,table = layui.table,$ = layui.$,admin=layui.admin,layer=layui.layer;

        table.render({
            elem:'#opinion-table',
            url:'/news/queryOpinion',
            page:true,
            request:{
                pageName:'current',
                limitName:'size'
            },
            cols:[[
                {field:'id',title:'ID',width:80},
                {field:'cname',title:'用户昵称',minWidth:200},
                {field:'cphone',title:'手机号码',minWidth:200},
                {field:'content',title:'评论内容',minWidth:200},
                {field:'status',title:'状态',minWidth:80,templet:"#status"},
                {field:'createtime',title:'发布时间',minWidth:200,templet:"<div>{{layui.util.toDateString(d.createtime,'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field:'endTime',title:'处理时间',minWidth:200,templet:"<div>{{layui.util.toDateString(d.endTime,'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {width:150,title:'操作',align:'center',fixed:'right',toolbar:'#table-operate'}
            ]]
        });

        table.on('tool(opinion-table)',function(obj){
            var data = obj.data;
            if(obj.event === 'handle'){
                layer.confirm('确定操作吗？', function(){
                    admin.req({
                        url: '/news/handleOpinionStatus',
                        data: {"id":data.id,"status":2},
                        done: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('opinion-table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                            }
                        }
                    });
                });
            }else if(obj.event === 'delete'){
                layer.confirm('确定删除吗？', function(){
                    admin.req({
                        url: '/news/deleteOpinion',
                        data: {"id":data.id},
                        done: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('opinion-table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                            }
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>